#include "rrrenderer.h"
#include <cstdio>

void RRRenderer::rrDraw(RRPrim *arg)
{
    memcpy(&prim1, arg, sizeof(RRPrim));
    yrotater.rrRotateY(&prim1);
    zmover.rrMoveZ(&prim1);
    projector.rrProjectiveTrans(&prim1);
    clipping.rrClipping(&prim1, &prim2);
    viewport.rrViewportTrans(&prim2);
    rasterizer.rrSetPrim(prim2);
    rasterizer.rrRast();
}

int RRRenderer::rrGetPointsNum()
{
    return rasterizer.rrGetPointsNum();
}

RRFragment RRRenderer::rrGetPoint(int index)
{
    return rasterizer.rrGetPoint(index);
}

void RRRenderer::rrPrintVert(int index)
{
    RRVertex temp;
    temp = prim2.rrGetVert(index);
    printf("%f, %f, %f\n", temp.x, temp.y, temp.z);
    printf("%f, %f, %f, %f\n", temp.c[0], temp.c[1], temp.c[2], temp.c[3]);
}

void RRRenderer::rrPrintRast()
{
    RRFragment temp;
    int pnum;
    pnum = rasterizer.rrGetPointsNum();
    for(int i=0; i<pnum; i++) {
        temp = rasterizer.rrGetPoint(i);
        printf("%d %d %f %f %f\n", temp.x, temp.y, temp.c[1], temp.c[2], temp.c[3]);
    }
}
